package com.weifangfirecontrolformal.weifangfirecontrolformal.web.web.internetofthings.firefightingiot;
import cn.hutool.json.JSONObject;
import com.weifangfirecontrolformal.weifangfirecontrolformal.common.base.BaseController;
import com.weifangfirecontrolformal.weifangfirecontrolformal.support.annotaion.Action;
import com.weifangfirecontrolformal.weifangfirecontrolformal.support.annotaion.At;
import com.weifangfirecontrolformal.weifangfirecontrolformal.support.model.RespEntity;
import com.weifangfirecontrolformal.weifangfirecontrolformal.web.service.internetofthings.firefightingiot.UploadFileService;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.multipart.MultipartFile;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.io.IOException;
import java.util.Map;

/**
 * 设备控制器
 */
@Action
@RequestMapping(value="uploadFile")
public class UploadFileController extends BaseController {
    @Resource
    public UploadFileService uploadFileService;

    /**
     * 设备导入模板下载
     * @param map
     * @return
     * @throws Exception
     */
    @At(value = "getTemplte", method = RequestMethod.GET)
    public ResponseEntity<byte[]> getTemplte(@RequestParam Map<String,Object> map) throws Exception {
        return uploadFileService.getTemplte(request);
    }

    /**
     * 设备导入
     * @param
     * @return
     * @throws Exception
     */
    @At(value = "/deviceImport", method = RequestMethod.POST, param = { "businessId","deviceClassify","deviceType","productId" })
    public RespEntity deviceImport(@RequestParam("file") MultipartFile file) throws IOException {
        return uploadFileService.deviceImport(file);
    }

    /**
     * 设备导入
     * @param
     * @return
     * @throws Exception
     */
    @RequestMapping(value = "/maintenanceDeviceImport", method = RequestMethod.POST)
    public RespEntity maintenanceDeviceImport(@RequestParam("file") MultipartFile file,String businessId, String partitionId, HttpServletRequest request) throws IOException {
        return uploadFileService.maintenanceDeviceImport(file,businessId,partitionId,request);
    }
    /**
     * 单位导入模板下载
     * @param map
     * @return
     * @throws Exception
     */
    @At(value = "getBusinessTemplate", method = RequestMethod.GET)
    public ResponseEntity<byte[]> getBusinessTemplate(@RequestParam Map<String,Object> map) throws Exception {
        return uploadFileService.getBusinessTemplate(request);
    }
    /**
     * 单位导入
     * @param
     * @return
     * @throws Exception
     */
    @RequestMapping(value = "/businessImport", method = RequestMethod.POST)
    public RespEntity businessImport(@RequestParam("file") MultipartFile file,String area, String areaName, HttpServletRequest request) throws IOException {
        return uploadFileService.businessImport(file,area,areaName,request);
    }
    /**
     * IP音柱和LED屏上传文件
     * @param
     * @return
     * @throws Exception
     */
    @RequestMapping(value = "/ipAudioOrLedVideoUpload", method = RequestMethod.POST)
    public RespEntity test(@RequestParam("file") MultipartFile file, String deviceClassify,String homeId, HttpServletRequest request) throws IOException {
        return uploadFileService.ipAudioOrLedVideoUpload(file,deviceClassify,homeId,request);
    }


    /**
     * 卸油证据链上传
     * @param
     * @return
     * @throws Exception
     */
    @RequestMapping(value = "/uploadChainOfEvidenceFile", method = RequestMethod.POST)
    public RespEntity uploadChainOfEvidenceFile(MultipartFile file) throws IOException {
        return uploadFileService.uploadChainOfEvidenceFile(file);
    }
    /**
     * 错误列表导出
     * @param
     * @return
     */
    @At(value = "downloadExcel", method = RequestMethod.GET)
    public ResponseEntity<byte[]> downloadExcel(@RequestParam("fileName") String fileName) throws Exception {
        return uploadFileService.downloadExcel(fileName,request);
    }

    /**
     * 设备导出
     * @param map
     * @return
     * @throws Exception
     */
    @At(value = "getDeviceTemplte", method = RequestMethod.GET)
    public ResponseEntity<byte[]> getDeviceTemplte(@RequestParam Map<String,Object> map) throws Exception {
        return uploadFileService.getDeviceTemplte(map,request);
    }

    /**
     * 报警记录导出
     * @param map
     * @return
     * @throws Exception
     */
    @At(value = "exportDeviceAlarmLog", method = RequestMethod.GET)
    public ResponseEntity<byte[]> exportDeviceAlarmLog(@RequestParam Map<String,Object> map) throws Exception {
        return uploadFileService.exportDeviceAlarmLog(map,request);
    }

    /**
     * @Author YangYu
     * @Description 显示控制装置历史数据记录导出
     * @Date Created in 10:09 2022/8/25
     * @Param [jsonParam]
     */

    @At(value = "exportWaterColumnBoxDataLog", method = RequestMethod.GET,param = { "number"})
    public RespEntity exportWaterColumnBoxDataLog(@RequestBody(required = false) JSONObject jsonParam) {
        return uploadFileService.exportWaterColumnBoxDataLog(jsonParam);
    }

    /**
     * @Author YangYu
     * @Description 设备导出
     * @Date Created in 10:09 2022/8/25
     * @Param [jsonParam]
     */

    @At(value = "getDeviceExport", method = RequestMethod.GET)
    public RespEntity getDeviceExport(@RequestBody(required = false) JSONObject jsonParam) {
        return uploadFileService.getDeviceExport(jsonParam);
    }

}
